package com.example.healkep.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.healkep.DoctorInfoActivity;
import com.example.healkep.R;
import com.example.healkep.bean.DoctorListBean;

import java.util.ArrayList;
import java.util.List;

public class DoctorListAdapter extends RecyclerView.Adapter<DoctorListAdapter.DemoViewHolder> {

    private List<DoctorListBean> mBeanList = new ArrayList<>();
    private Context mContext;

    public DoctorListAdapter(Context context, List<DoctorListBean> beanList) {
        this.mContext = context;
        this.mBeanList = beanList;
    }

    @NonNull
    @Override
    public DemoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.doctot_list_item, parent, false);

        return new DemoViewHolder(view);
    }


    @Override
    public void onBindViewHolder(@NonNull DemoViewHolder holder, int position) {
        DoctorListBean doctorListBean = mBeanList.get(position);
        holder.nameTv.setText(doctorListBean.getName());
        holder.nameTv.setOnClickListener(view -> {
            DoctorInfoActivity.start(mContext, doctorListBean);
        });
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        if (mBeanList != null) {
            return mBeanList.size();
        }else {
            return 0;
        }
    }

     static class DemoViewHolder extends RecyclerView.ViewHolder{
        private TextView nameTv;
        public DemoViewHolder(@NonNull View itemView) {
            super(itemView);
            nameTv = itemView.findViewById(R.id.name_tv);
        }
    }
}
